
<script>
	export default {
		onLaunch: function() {
			const accountInfo = uni.getAccountInfoSync();
			console.log(accountInfo)
			if(accountInfo.miniProgram.version != undefined) {
				uni.setStorageSync('version', accountInfo.miniProgram.version);
			}
			let userInfor = uni.getStorageSync('userInfor')
			if(!userInfor.userId) {
				uni.redirectTo({
					url: '/pages/login/login'
				});
			}
			else {
				if(userInfor.isDerive) {
					uni.switchTab({
						url: '/pages/work/index'
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
				
			}
			this.updateProgram()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 更新小程序
			updateProgram() {
				/* const accountInfo = uni.getAccountInfoSync(); */
			  if (uni.canIUse('getUpdateManager')) {
			    const updateManager = uni.getUpdateManager();
			    updateManager.onCheckForUpdate((res) => {
			      if (res.hasUpdate) {
			        updateManager.onUpdateReady(() => {
			          uni.showModal({
			            title: '更新提示',
			            content: '新版本已准备好，是否重启应用？',
			            success: (res) => {
			              if (res.confirm) {
			                // 强制重启小程序
			                updateManager.applyUpdate();
							
			              }
			            },
			          });
			        });
			
			        updateManager.onUpdateFailed(() => {
			          uni.showModal({
			            title: '更新失败',
			            content: '新版本下载失败，请检查网络后重试',
			            showCancel: false,
			          });
			        });
			      }
			    });
			  } else {
			    uni.showModal({
			      title: '提示',
			      content: '当前微信版本过低，无法使用更新功能，请升级到最新微信版本后重试。',
			      showCancel: false,
			    });
			  }
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	page {
	  background-color: rgba(237, 237, 237, 0.9);  /* 如浅灰色背景 */
	}
	@import '@/style/index.scss'
	/* 隐藏全局滚动条 */
	::-webkit-scrollbar {
	  display: none !important;
	  width: 0 !important;
	  height: 0 !important;
	  background-color: transparent !important;
	}
	/* 处理部分平台兼容性 */
	uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
	  display: none !important;
	}

</style>
